/**
 * Created by kevin on 16/8/16.
 */
var eosi = window.eosi || {};
this.eosi.fotile = this.eosi.fotile || {};
//this.eosi.fotile = this.eosi.fotile || {};
//this.eosi.fotile = function(name) {
//    this.name = name;
//};

(function (window) {
    // the application
    function Fotileintro(master) {
        this.Container_constructor();
        this.version = master.version;
        this.init(master);
    }
    var p = createjs.extend(Fotileintro, createjs.Container);

    // public methods:
    p.init = function (master) {
        this.fotile = master;
        console.log("I'm Master wait!!!");
        this.loadFirsrMaster();
    }

    //UI
    p.setupUI = function (){


    }

    //加载wait
    p.loadFirsrMaster = function (){
        var wait = this;
        var load=[
            {src:"static/master/intro/bg.png",id:"bg"},
            {src:"static/master/intro/f_1.png",id:"f1"},
            {src:"static/master/intro/f_2.png",id:"f2"},
            {src:"static/master/intro/f_3.png",id:"f3"},
            {src:"static/master/intro/f_4.png",id:"f4"},
            {src:"static/master/intro/f_5.png",id:"f5"},
            {src:"static/master/intro/hua1.png",id:"hua1"},
            {src:"static/master/intro/hua2.png",id:"hua2"},
            {src:"static/master/intro/hua3.png",id:"hua3"},
            {src:"static/master/intro/hua4.png",id:"hua4"},]
        Fotileloader = new eosi.fotile.Fotileloader(this.fotile,load,function(){
            wait.setupLoaderUI();
        },1);
        container.addChild(Fotileloader);

        p.setupLoaderUI = function (){
            _this=this;
            var bg = new createjs.Bitmap(this.fotile.master_UILoader.getResult("bg"));
            var f1 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("f1"));
            var f2 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("f2"));
            var f3 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("f3"));
            var f4 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("f4"));
            var f5 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("f5"));
            var hua1 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("hua1"));
            var hua2 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("hua2"));
            var hua3 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("hua3"));
            var hua4 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("hua4"));

            var v_w = bg.getBounds().width;
            var v_h = bg.getBounds().height;
            var w = this.fotile.getWidth();
            var h = this.fotile.getHeight();
            var ratio_y = h/v_h;
            var ratio_x =  w/v_w;
            bg.setTransform(0,0,ratio_x,ratio_y);
            bg.x=0;
            bg.y=0;

            f1.setTransform(0,0,ratio_x,ratio_x);
            f1.x = (this.fotile.getWidth()/2)-(f1.getBounds().width*ratio_x/2);
            f1.y = (this.fotile.getHeight()*0.29)-(f1.getBounds().height*ratio_x/2);
            f1.alpha = 1;

            f2.setTransform(0,0,ratio_x,ratio_x);
            f2.x = (this.fotile.getWidth()/2)-(f2.getBounds().width*ratio_x/2);
            f2.y = (this.fotile.getHeight()*0.42)-(f2.getBounds().height*ratio_x/2);
            f2.alpha = 1;

            f3.setTransform(0,0,ratio_x,ratio_x);
            f3.x = (this.fotile.getWidth()/2)-(f3.getBounds().width*ratio_x/2);
            f3.y = (this.fotile.getHeight()*0.525)-(f3.getBounds().height*ratio_x/2);
            f3.alpha = 1;

            f4.setTransform(0,0,ratio_x,ratio_x);
            f4.x = (this.fotile.getWidth()/2)-(f4.getBounds().width*ratio_x/2);
            f4.y = (this.fotile.getHeight()*0.625)-(f4.getBounds().height*ratio_x/2);
            f4.alpha = 1;


            f5.setTransform(0,0,ratio_x,ratio_x);
            f5.x = (this.fotile.getWidth()/2)-(f5.getBounds().width*ratio_x/2);
            f5.y = (this.fotile.getHeight()*0.74)-(f5.getBounds().height*ratio_x/2);
            f5.alpha = 1;

            hua1.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            hua1.rotation =-120;
            hua1.x =this.fotile.getWidth()*0.3-hua1.getBounds().width*ratio_x*1.1/2;
            hua1.y = (this.fotile.getHeight()*0.24)-(hua1.getBounds().height*ratio_x*1.1/2);
            hua1.alpha = 1;

            hua2.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            hua2.x =this.fotile.getWidth()*0.8-hua2.getBounds().width*ratio_x*1.1/2;
            hua2.y = (this.fotile.getHeight()*0.832)-(hua2.getBounds().height*ratio_x*1.1/2);
            hua1.alpha = 1;

            hua3.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            hua3.x =0;
            hua3.y = (this.fotile.getHeight())-(hua3.getBounds().height*ratio_x*1.1);
            hua3.alpha = 1;

            hua4.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            hua4.x =this.fotile.getWidth()*0.9-hua4.getBounds().width*ratio_x*1.1/2;
            hua4.y = (this.fotile.getHeight()*0.35)-(hua4.getBounds().height*ratio_x*1.1/2);
            hua4.alpha = 1;




            this.addChild(bg);
            this.addChild(hua1);
            this.addChild(hua2);
            this.addChild(hua3);
            this.addChild(hua4);
            this.addChild(f1);
            this.addChild(f2);
            this.addChild(f3);
            this.addChild(f4);
            this.addChild(f5);
            stage.update();
            // this.clearLoading=function (){
            //     this.removeChild(bg);
            //     this.removeChild(text_box_bg);
            //     this.removeChild(logo);
            //     this.removeChild(a_1);
            //     this.removeChild(a_2);
            //     this.removeChild(a_3);
            //     this.removeChild(a_4);
            //     this.removeChild(a_5);
            //     this.removeChild(a_6);
            //     this.removeChild(bn);
            //     this.removeChild(downarrow);

            //     document.getElementById("canvas").removeEventListener("click",clickPlayBn);
            //     container.removeChild(master);
            //     stage.update();
            // }

        }

    }
    // add MyApp to myNameSpace
    window.eosi.fotile.Fotileintro = createjs.promote(Fotileintro, "Container");
}(window));
